package com.woniu.utils;

import org.springframework.http.HttpStatus;

import java.util.HashMap;

public class ResponseMyEntity extends HashMap {
    public enum ResponseStatus {
        CODE("code"), MSG("msg"), DATA("data");

        private final String value;

        ResponseStatus(String value) {
            this.value = value;
        }

        public String value() {
            return this.value;
        }
    }

    private static final String CODE = ResponseStatus.CODE.value();
    private static final String MSG = ResponseStatus.MSG.value();
    private static final String DATA = ResponseStatus.DATA.value();

    public ResponseMyEntity() {}

    public ResponseMyEntity(Object data) {
        put(CODE, HttpStatus.OK.value());
        put(MSG, "执行成功");
        put(DATA, data);
    }

    public ResponseMyEntity(int code, String message) {
        put(CODE, code);
        put(MSG, message);
    }

    public ResponseMyEntity(int code, String message, Object data) {
        put(CODE, code);
        put(MSG, message);
        if (data != null) {
            put(DATA, data);
        }
    }

    public static final ResponseMyEntity SUCCESS = new ResponseMyEntity(HttpStatus.OK.value(), "执行成功！");
    public static final ResponseMyEntity ERROR = new ResponseMyEntity(HttpStatus.INTERNAL_SERVER_ERROR.value(), "执行失败！");
}
